/*     */ package com.zimbra.cs.service.mail;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.Appointment;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.CalendarItem.AlarmData;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import com.zimbra.soap.DocumentHandler;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Iterator;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DismissCalendarItemAlarm
/*     */   extends DocumentHandler
/*     */ {
/*  55 */   private static final String[] sCalItemElems = { "appt", "task" };
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  60 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  61 */     Mailbox mbox = getRequestedMailbox(zsc);
/*  62 */     String acctId = mbox.getAccountId();
/*  63 */     Account authAcct = getAuthenticatedAccount(zsc);
/*  64 */     OperationContext octxt = getOperationContext(zsc, context);
/*     */     
/*  66 */     Element response = getResponseElement(zsc);
/*  67 */     for (String calItemElement : sCalItemElems) {
/*  68 */       Iterator<Element> iter = request.elementIterator(calItemElement);
/*  69 */       while (iter.hasNext()) {
/*  70 */         Element calItemElem = (Element)iter.next();
/*  71 */         ItemId iid = new ItemId(calItemElem.getAttribute("id"), zsc);
/*  72 */         long dismissedAt = calItemElem.getAttributeLong("dismissedAt");
/*     */         
/*     */ 
/*  75 */         ZimbraLog.calendar.info("<DismissCalendarItemAlarm> id=%s, at=%d", new Object[] { iid.toString(), Long.valueOf(dismissedAt) });
/*     */         
/*  77 */         Mailbox ciMbox = null;
/*  78 */         String ciAcctId = iid.getAccountId();
/*  79 */         if ((ciAcctId == null) || (ciAcctId.equals(acctId))) {
/*  80 */           ciMbox = mbox;
/*     */         }
/*     */         else
/*     */         {
/*  84 */           if (AccountUtil.isZDesktopLocalAccount(zsc.getAuthtokenAccountId()))
/*  85 */             ciMbox = MailboxManager.getInstance().getMailboxByAccountId(ciAcctId, false);
/*  86 */           if (ciMbox == null)
/*  87 */             throw MailServiceException.PERM_DENIED("cannot dismiss alarms of a shared calendar");
/*     */         }
/*  89 */         int calItemId = iid.getId();
/*  90 */         ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
/*     */         try {
/*  92 */           ciMbox.dismissCalendarItemAlarm(octxt, calItemId, dismissedAt);
/*     */           
/*  94 */           CalendarItem calItem = ciMbox.getCalendarItemById(octxt, calItemId);
/*     */           Element calItemRespElem;
/*  96 */           Element calItemRespElem; if ((calItem instanceof Appointment)) {
/*  97 */             calItemRespElem = response.addElement("appt");
/*     */           } else
/*  99 */             calItemRespElem = response.addElement("task");
/* 100 */           calItemRespElem.addAttribute("calItemId", iid.toString(ifmt));
/*     */           
/* 102 */           boolean hidePrivate = !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
/* 103 */           boolean showAll = (!hidePrivate) || (calItem.isPublic());
/* 104 */           if (showAll) {
/* 105 */             CalendarItem.AlarmData alarmData = calItem.getAlarmData();
/* 106 */             if (alarmData != null) {
/* 107 */               ToXML.encodeAlarmData(calItemRespElem, calItem, alarmData);
/*     */             }
/*     */           }
/*     */         }
/*     */         catch (MailServiceException.NoSuchItemException nsie)
/*     */         {
/* 113 */           Element calItemRespElem = response.addElement(calItemElement);
/* 114 */           calItemRespElem.addAttribute("calItemId", iid.toString(ifmt));
/*     */         }
/*     */       }
/*     */     }
/* 118 */     return response;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/DismissCalendarItemAlarm.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */